package com.huatai.vba.execute.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.huatai.vba.common.utils.ZipUtil;
import com.huatai.vba.dal.model.VbaFileAction;
import com.huatai.vba.properties.VbaEnv;

@Service("icbcStartCreateDbfFileActionExecutor")
public class IcbcStartCreateDbfFileActionExecutor extends AbstractIcbcActionExecutor {

	private static final Logger logger = LoggerFactory.getLogger(IcbcStartCreateDbfFileActionExecutor.class);

	@Override
	public void execute(VbaFileAction action) {
		try {
			String disc = VbaEnv.isTest ? "D" : "H";
			String disc1 = VbaEnv.isTest ? "D" : "Y";

			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/tsgh13812.dbf");
			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/GH13812_zr.dbf");
			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/tssjshb.dbf");
			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/tssjsfx100200.dbf");
			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/tsjsmxjs946.dbf");

			// '增加原始明细，回报，发行文件
			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/sjsfx.dbf");
			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/sjshb.dbf");
			dBFConvertDBService.convertDBToDBF(disc + ":/pro_data/dbf/sjsmx1.dbf");

			// '打包文件路径,可以自己设
			String yyyy_MM_dd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
			String yyyy = yyyy_MM_dd.substring(0, 4);
			String yyMM = yyyy_MM_dd.substring(2, 7).replace("-", "");
			String yyMMdd = yyyy_MM_dd.substring(2).replace("-", "");
			// '深交所路径
			String strSjsPath = disc + ":/vsat3/dbf/" + yyyy + "/" + yyMM + "/" + yyMMdd + "/";
			String rarFileName = disc1 + ":/send/tsgh13812_" + yyMMdd + ".rar ";
			List<String> fileNames = Lists.newArrayList();
			fileNames.add(disc + ":/pro_data/dbf/tsgh13812.dbf ");
			fileNames.add(disc + ":/pro_data/dbf/tssjshb.dbf ");
			fileNames.add(disc + ":/pro_data/dbf/tssjsfx100200.dbf ");
			fileNames.add(disc + ":/pro_data/dbf/tsjsmxjs946.dbf ");
			fileNames.add(strSjsPath + "sjsfx.dbf ");
			fileNames.add(strSjsPath + "sjshb.dbf ");
			fileNames.add(strSjsPath + "sjsmx1.dbf ");
			ZipUtil.zip(rarFileName, (String[]) fileNames.toArray());
			logger.info("压缩文件完成");

		} catch (Exception ex) {
			logger.error("系统异常", ex);
		}

	}

}
